{$R-}

(*
	peek -- a sample HyperCard external function

	To compile and link this file using Macintosh Programmer's Workshop,

	pascal -w Peek.p
	pascal -w XCmdUtil.p
	asm -w XCmdUtil.a
	link -m ENTRYPOINT -o HyperCommands -rt XFCN=0 -sn Main=Peek Peek.p.o ¶
	  XCmdUtil.p.o XCmdUtil.a.o "{MPW}"Libraries:interface.o

*)

{$S Peek } 	{ Segment name must be the same as the command name. }

UNIT DummyUnit;

INTERFACE

USES MemTypes, HyperXCmd, XCmdUtil;
  
PROCEDURE EntryPoint(paramPtr: XCmdPtr);

IMPLEMENTATION

PROCEDURE Peek(paramPtr: XCmdPtr); 								FORWARD;

  PROCEDURE EntryPoint(paramPtr: XCmdPtr);
  BEGIN
    Peek(paramPtr);
  END;

  PROCEDURE Peek(paramPtr: XCmdPtr);
  VAR peekAddr,peekSize,peekVal: LongInt;	
	  str: Str255;
  BEGIN
	WITH paramPtr^ DO
	  BEGIN
		{ first param is addr }
		ZeroToPas(params[1]^,str);
		peekAddr := StrToNum(str);
		
		{ second param, if given, is size }
		peekSize := 1;
		IF paramCount = 2 THEN
		  BEGIN
		    ZeroToPas(params[2]^,str);
		    peekSize := StrToNum(str);
		  END;
		
		CASE peekSize OF
		  1: peekVal := BAND($000000FF,Ptr(peekAddr)^);
		  2: peekVal := BAND($0000FFFF,WordPtr(BAND($FFFFFFFE,peekAddr))^);
		  4: peekVal := LongPtr(BAND($FFFFFFFE,peekAddr))^;
		  OTHERWISE peekVal := 0;
		END;
		
		str := NumToStr(peekVal);
		returnValue := PasToZero(str);
	  END;
  END;


END.



